package goods

import (
	"enjoy_xxz/base"
	"enjoy_xxz/formdata"
	"enjoy_xxz/internal/server/goods"
	"github.com/gin-gonic/gin"
)

// 商品详情
func GoodsDetail(c *gin.Context) {
	var data formdata.GoodsDetail
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	list, err := goods.GoodsDetail(data)
	base.RespData(c, list, err)
}

// 查询skux信息
func GetSkuInfo(c *gin.Context) {
	var data formdata.GoodsDetail
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	skuInfo, err := goods.GetSkuInfo(data)
	base.RespData(c, skuInfo, err)
}

// 商品搜索列表
func SearchGoodsList(c *gin.Context) {
	var data formdata.GoodsSearch
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	infoList, err := goods.SearchGoodsList(data)
	base.RespData(c, infoList, err)
}

// 分类位置列表
func CategoryLocationList(c *gin.Context) {
	var data formdata.GoodsCategoryLocation
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	list, err := goods.CategoryLocationList(data)
	base.RespData(c, list, err)
}

// 分类列表
func CategoryList(c *gin.Context) {
	list, err := goods.CategoryList()
	base.RespData(c, list, err)
}

// 分类id查询商品
func CategoryByIDGoodsInfo(c *gin.Context) {
	var data formdata.CategoryByIDGoodsInfo
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	infoList, err := goods.CategoryIdByGoodsInfo(data)
	base.RespData(c, infoList, err)
}
